total 80240
drwxr-xr-x@ 23 adam staff 736B Mar 31 16:51 .
drwxr-xr-x@ 11 adam staff 352B Mar 24 12:10 ..
-rw-r--r--@ 1 adam staff 48K Mar 8 17:44 git.png
-rw-r--r--@ 1 adam staff 1.2M Mar 14 11:55 git_branch_create.gif
-rw-r--r--@ 1 adam staff 1.1M Mar 14 11:55 git_branch_local_merge.gif
-rw-r--r--@ 1 adam staff 5.5M Mar 14 11:55 git_branch_pull_request.gif
-rw-r--r--@ 1 adam staff 1.3M Mar 13 14:10 git_clone_vscode.gif
-rw-r--r--@ 1 adam staff 1.0M Mar 13 14:04 git_init_repo.gif
-rw-r--r--@ 1 adam staff 3.4M Mar 13 16:22 git_merge.gif
-rw-r--r--@ 1 adam staff 142K Mar 13 16:35 git_merge_conflict.png
-rw-r--r--@ 1 adam staff 59K Mar 13 16:35 git_merge_conflict_combination.png
-rw-r--r--@ 1 adam staff 58K Mar 13 16:35 git_merge_conflict_editor.png
-rw-r--r--@ 1 adam staff 987K Mar 13 15:34 git_stage_commit_push.gif
-rw-r--r--@ 1 adam staff 9.4K Mar 13 17:37 gitignore.png
-rw-r--r--@ 1 adam staff 24M Mar 31 16:43 lecture_2.html
-rw-r--r--@ 1 adam staff 18K Mar 31 16:50 lecture_2.qmd
-rw-r--r-- 1 adam staff 18K Mar 31 16:51 lecture_2.rmarkdown
-rw-r--r--@ 1 adam staff 49K Mar 23 15:29 man_ls.png
-rw-r--r--@ 1 adam staff 111K Mar 8 17:44 phd_git_comic.gif
-rw-r--r--@ 1 adam staff 17K Mar 13 17:07 project_folder_structure.png
-rw-r--r--@ 1 adam staff 150K Mar 13 17:40 readme.png
-rw-r--r--@ 1 adam staff 12K Mar 14 11:21 shell_mac.png
-rw-r--r--@ 1 adam staff 32K Mar 14 11:21 shell_win.png
Short shell intro
More commands
mv <file> <destination> moves
cp <file> <destination> copies
rm <file> removes
mkdir <directory> creates a directory, rmdir removes
find searches
Short shell intro
man for manual
man ls
Use space to browse, press h for help and q to quit.
Short shell intro
This was just a very basic introduction
Hopefully the sight of a command line will not scare you from now on
Check out the resources at the end of today’s talk if you want to learn more!
Follow the instructions in Problem set 0 to set up your Git user.name and user.email. Otherwise you will get an error when pressing “Commit”.
Basic Git workflow
Stage and commit in two steps, why?
git commit just commits staged files
We use git add <file> to chose what to commit
Can even git add --patch <file> to stage parts
This allows to divide up changes into multiple commits based on features/components
Basic Git workflow
What we just did
Initialized repo on GitHub, cloned to local machine
Edited the README file in the repo
Staged the edit: told Git we want to record the change we just made
Committed (= recorded) the edit into the repo history with a helpful message
Pushed the edited repo to the upstream remote (=GitHub).
Basic Git workflow
Credentials
Locally, Git uses information stored in user.name and user.email to tell others who you are.
When Pulling/pushing changes to/from GitHub, VS Code needs your login. Anyone can clone a public repository, but only you (and those you invite) can push changes to your repo.
Remember: Git is not backup. You should have a backup solution too.
Merge conflicts
Project management
Short shell intro
Version control
Basic Git workflow
Merge conflicts
Branches
Merge conflicts
Code change by multiple sources
Two contributors have made changes to the same file. Git stops merge to not overwrite changes. Requires manual conflict resolution.
Merge conflicts
Merge conflicts
Resolving conflicts using the merge editor
Merge conflicts
Resolving conflicts using the merge editor
Merge conflicts
Manual edits
VS Code provides a great UI for resolving merge conflicts, but you can also do it manually by editing the conflicting files. If you open the file you will see something like this. The strange characters are Git’s way of highlighting the merge conflict.
# test-repo<<<<<<< HEADA repo for testing and having fun.=======A repo for playing around.>>>>>>> 814e09178910383c128045ce67a58c9c1df3f558.A not so cool change to the README file.
You fix the conflict manually by simply removing the characters and chosing the text you prefer.
Branches
Project management
Short shell intro
Version control
Basic Git workflow
Merge conflicts
Branches
Branches
Want to test a large change, but unsure it will work?
Create a new branch to try it out, then just revert to main if it fails.
Keep track of your changes (with commits) without disturbing your collaborators with unfinished code.
If you are happy with your changes, merge them to the main branch.
Branching is awesome, use it!
Branches
Creating a new branch in VS Code
git switch --create test-branch
Branches
Merging branches locally
git switch mastergit merge test-branch
Branches
Merging branches with pull requests
Git advice
Commit often, work in small features
Don’t: “New data processing script”
Do: “Removed duplicates from survey data”
Push changes when you want your collaborators to see
When connecting the private key encrypts a message that can only be validated by the corresponding public key
SSH
Generating a key pair
To generate an SSH key pair and register the public key with GitHub, follow these steps. For detailed instructions, see GitHub Docs.
ssh-keygen-t ed25519 -C"your_email@example.com"
Press Enter to accept the default file location. When prompted, enter a secure passphrase (your terminal will not show characters as you type).
SSH
Storing the passphrase using ssh-agent
You should secure your keys with a passphrase. But it might become annoying having to type the passphrase each time you use the SSH key. Instead, you can use a ssh-agent to store the passphrase for you. On Mac/Linux this is easy:
eval"$(ssh-agent-s)"ssh-add ~/.ssh/id_ed25519
On Windows, it’s more complicated. I’ve included the instructions in Problem Set 0 but let’s go through them together now.
SSH
Connecting to Github over SSH
To use SSH with Github you first need to add your public key to your GitHub profile. Go to settings and “SSH and GPG keys” to add it.
Afterwards, run:
ssh-T git@github.com
Hi adamaltmejd! You've successfully authenticated, but GitHub does not provide shell access.
Now you can clone repositories using SSH rather than https.
We will get back to how to use SSH to connect to servers later in the course.